# TODO: Add comment
# 
# Author: Forever
###############################################################################


library(RPostgreSQL)
dr=dbDriver("PostgreSQL")



query="SELECT min(aqstime) as start_date,max(aqstime) as end_date,count(id) as total FROM apom."
table = c("satresampmod04","satresampmod04aerosoltype","satresampmod07pressure","satresampmod07temperature","satresampmyd04","satresampmyd04aerosoltype","satresampmyd07pressure","satresampmyd07temperature","grdpmhiscem_data")
con=dbConnect(dr,dbname="fimo",host="192.168.100.4",port=5432,user="rasdaman",password="rasdaman")
data=data.frame()
for (str in table) {
	rs=dbSendQuery(con,paste(query,str,sep=""))
	data=rbind(data,data.frame(str,fetch(rs,n=-1)))
}
rs=dbSendQuery(con,paste(query,"grdaeraot_data where processtype =2",sep=""))
str = "grdaeraot_data 2"
data=rbind(data,data.frame(str,fetch(rs,n=-1)))

rs=dbSendQuery(con,paste(query,"grdaeraot_data where processtype =1.5",sep=""))
str = "grdaeraot_data 1.5"
data=rbind(data,data.frame(str,fetch(rs,n=-1)))

write.csv(data,"C:/dbstatis.csv")


